<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="准考证号">
              <a-input placeholder="请输入..." v-model="queryParam.ksbmh"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="考生姓名">
              <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="业务科一成绩">
               <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zycjfhy">
                    <a-select-option v-for="i in getSymbol" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ywkycj"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="业务科二成绩">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zycjfhe">
                    <a-select-option v-for="i in getSymbol" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ywkecj"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="加试科目成绩">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.jscjfh">
                    <a-select-option v-for="i in getSymbol" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.jskmycj"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="考生类型">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.kslx">
                <a-select-option v-for="i in TYPE0422" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="招生年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsnj" @change="xnChange">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="录取状态">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.lqzt">
                <a-select-option v-for="i in TYPE0421" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :disabled="selectMenu.yx.length === 1" :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkyxsm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkzydm" @change="zyChange">
                <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
            <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
              <a-form-item label="研究方向">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkyjfxm">
                  <a-select-option v-for="i in selectMenu.fx" :key="i.id" :value="i.yjfxm">{{
                    i.yjfxm.substring(i.yjfxm.length-2) +"-"+ i.yjfxmc }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
              <a-form-item label="数据排序方式">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.sortOrder">
                  <a-select-option v-for="i in selectMenu.sort" :key="i.value" :value="i.value">{{ i.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :sm="{span:16}" :xl="{span:8}" style="padding-top: 29px;">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a-button @click="queryParam = {}" style="margin:0 10px">重置</a-button>
            <!-- <a-button type="primary" @click="handleSubmit" :disabled='isdisabled'>提交</a-button> -->
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
     <!-- <a-alert class="card"  message="温馨提示：请维护完本院系所有信息后再提交、一旦提交禁止再进行任何修改" banner /> -->
    <a-card class="card" :bordered="false">
    <a-alert :message="'总条数：' + pagination.total" type="info" show-icon />

    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"

      :pagination="pagination"
      @change="handleTableChange"
      :scroll="{ x: 1500 }"
    >
    <template slot="action" slot-scope="text,record">
        <a @click="record.ableToEdit  && record.lqzt=='未录取'  && handleReview(record.id)" :style="!record.ableToEdit || record.lqzt=='拟录取'?'color:#999' : ''">审查修改</a>
      <a-divider type="vertical" />
        <a @click="record.ableToEdit && record.lqzt=='未录取' && record.lqlbm!=''  && handleEnroll(record.id,record.lqzt)" :style="!record.ableToEdit || record.lqzt=='拟录取' || record.lqlbm==''? 'color:#999' : ''">录取</a>
      <a-divider type="vertical" />
        <a @click=" record.ableToCancel && record.lqzt=='拟录取' && handleCancelEnroll(record.id,record.lqzt)" :style="!record.ableToCancel || record.lqzt=='未录取' ?'color:#999' : ''">取消录取</a>
      </template>
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
       <template slot="ksbh" slot-scope="text,record">
        <a @click="handlePreview(record)">{{text}}</a>
      </template>
    </a-table>
          <!-- 查看 -->
    <examinee :previewVisible="previewVisible" :info="examineeData" @close="handleClosePreview"></examinee>
  <!-- 审查 -->
  <plan-review @close="handleReviewClose" @success="handleReviewSuccess" :planReviewVisible="planReviewVisible" :info="planReviewData" ></plan-review>
    </a-card>
</div>
</template>

<script>
import PlanReview from './planReview'
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'
import Examinee from '../../examinee/detail'

const selectArr = ['TYPE0126', 'TYPE0422', 'TYPE0421', 'TYPE0072']

export default {
  components: {
    STable,
    PlanReview,
    Examinee
  },
  data () {
    return {
      advanced: true,
      planReviewVisible: false,
       previewVisible:false,
      examineeData:'',
      loading: false,
      data: [],
      isdisabled:false,
      lqAble:'',
     
      // 查询参数
      queryParam: {
        zycjfhy:1,
        zycjfhe:1,
        jscjfh:1,
        zsnj:'',
      },
      postParams: {

      },
      getSymbol:[
        {
          code:0,
          name:'<='
        },
        {
          code:1,
          name:'>='
        }
      ],
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '准考证号',
          dataIndex: 'ksbh',
           scopedSlots: { customRender: 'ksbh' },
        },
        {
          title: '姓名',
          dataIndex: 'ksxm',
          width:100
        },
        {
          title: '录取院系',
          dataIndex: 'bkyxsmc'
        },
        {
          title: '录取专业代码',
          dataIndex: 'bkzydm'
        },
        {
          title: '录取专业',
          dataIndex: 'bkzymc'
        },
        {
          title: '研究方向',
          dataIndex: 'bkyjfxmc'
        },
        {
          title: '业务课一',
          dataIndex: 'ywkycj'
        },
        {
          title: '业务课二',
          dataIndex: 'ywkecj'
        },
        {
          title: '加试科目',
          dataIndex: 'jskmycj'
        },
        {
          title: '综合评定',
          dataIndex: 'zhpd'
        },
        {
          title: '录取导师',
          dataIndex: 'bkdsyxm'
        },
        {
          title: '录取类别',
          dataIndex: 'lqlbm'
        },
        {
          title: '录取状态',
          dataIndex: 'lqzt'
        },
        {
          title: '学制',
          dataIndex: 'xz'
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 240,
          scopedSlots: { customRender: 'action' }
        }
      ],
      // custom table alert & rowSelection
      options: {
        alert: { show: false },
        rowSelection: {
          onChange: (selectedRowKeys, selectedRows) => {
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          },
          onSelect: (record, selected, selectedRows) => {
            console.log(record, selected, selectedRows)
          },
          onSelectAll: (selected, selectedRows, changeRows) => {
            console.log(selected, selectedRows, changeRows)
          }
        }
      },
      selectMenu: {
        yx: [], // 院系
      },
      planReviewData: {},
      pagination:{
        current:1,
        showTotal: (() => {return `共 ${this.pagination.total} 条`}),
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '30','40'],
          // 改变pageSize后触发
        onShowSizeChange: (current, pageSize) => this.pagination.pageSize = pageSize,
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'], // 年级
      TYPE0422: state => state.app['TYPE0422'],
      TYPE0421: state => state.app['TYPE0421']
    })
  },
  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu.yx= res[0].data
        this.queryParam.bkyxsm=res[0].data[0].dwh;
        this.$api.base.majorAll({lsdwh: this.queryParam.bkyxsm}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
        this.$api.base.getSchoolYear().then(res => {
          this.queryParam.zsnj = res.data.doctoralAdmissionYear
          this.loadData({
            pageNum: 1,
            pageSize: 10
          })
        })


      })
      this.$api.base.getSort().then(res => {
        this.$set(this.selectMenu, 'sort', res.data)
        console.log(this.selectMenu.sort)
      })

    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'bkzydm', '')
      this.$set(this.queryParam, 'bkyjfxm', '')
      this.$set(this.selectMenu,'zy','')
      this.$set(this.selectMenu,'fx','')
      if(code){
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
      }
    },
     // 选择专业
    zyChange (code) {
      this.$set(this.queryParam, 'bkyjfxm', '')
      this.$set(this.queryParam,'fx','')
      if(code){
      let params={sszym: code,ssyxm: this.queryParam.bkyxsm,xwccm:3,zsxn:this.queryParam.zsnj}
      this.$api.base.researchAll(params).then(res => {
        this.$set(this.selectMenu, 'fx', res.data)
      })
      }
    },
    xnChange(code){
      if(this.queryParam.bkzydm && code){
       this.$set(this.queryParam, 'bkyjfxm', '')
       this.$set(this.selectMenu,'fx','')
        let params={sszym: this.queryParam.bkzydm,ssyxm: this.queryParam.bkyxsm,xwccm:3,zsxn:code}
        this.$api.base.researchAll(params).then(res => {
        this.$set(this.selectMenu, 'fx', res.data)
      })
     }
    },
   // 加载数据
    loadData(parameter = {}) {
      if(!parameter.pageNum){
         this.pagination.current = 1
         parameter.pageNum = 1
       }
      let params = Object.assign(this.queryParam, parameter)
      this.loading = true;
      this.$api.doctorRecruit.enrollList(params).then(res => {
        // console.log(res)
         const pagination = { ...this.pagination
        };
        pagination.total = 0
        if (res.data && res.data.total) {
          pagination.total = res.data.total;
        }
        this.data = []
        this.pagination = pagination;
        if (res.data && res.data.rows.length) {
          this.data = res.data.rows;
          this.data.forEach(item =>{
            if(item.lqdsxm){
              item.bkdsyxm = item.lqdsxm
            }
          })
      //     this.$api.doctorRecruit.enrollAble({bkyxsm:this.queryParam.bkyxsm,zsnj:this.queryParam.zsnj}).then(res=> {
      //       if(res.data==false){
      //         this.isdisabled=true;
      //       }else{
      //         this.isdisabled=false;
      //       }
      // })
        }
        this.loading = false;
      })
    },
    // 分页
			handleTableChange(pagination, filters, sorter) {
				console.log(pagination);
				const pager = { ...this.pagination
				};
				pager.current = pagination.current;
				this.pagination = pager;
				this.loadData({
					pageSize: pagination.pageSize,
					pageNum: pagination.current
				});
			},
    // 选择招生年度
    zsndChange () {

    },
    // 导出
    handleExport () {
      this.$export('admissions/bsnlqrymd/nlqexport',this.queryParam)
    },
    // 审查
    handleReview (data) {
      this.$api.doctorRecruit.enrollId(data).then(res=>{
        this.planReviewData=res.data;
      })
      this.planReviewVisible = true
    },
    // 录取
    handleEnroll (id,lqzt) {
      let _this=this
      if(lqzt=='未录取'){
        lqzt='02'
      }else{
        lqzt='01'
      }
      this.$confirm({
         title: '确定录取?',
         onOk() {
            _this.$api.doctorRecruit.enrollAdm({id:id,lqzt:lqzt}).then(res=>{
            _this.loadData({
              pageSize:10,
              pageNum:_this.pagination.current
            })
          })
         },
         onCancel() {
           console.log('Cancel');
         },
         class: 'test',
       });

    },
    // 取消录取
    handleCancelEnroll (id,lqzt) {
      let _this=this
      if(lqzt=='未录取'){
        lqzt='02'
      }else{
        lqzt='01'
      }
      this.$confirm({
         title: '确定取消录取?',
         onOk() {
           _this.$api.doctorRecruit.enrollAdm({id:id,lqzt:lqzt}).then(res=>{
            _this.loadData({
          pageSize:10,
          pageNum:_this.pagination.current
        })
      })
         },
         onCancel() {
           console.log('Cancel');
         },
         class: 'test',
       });

    },
    // 提交
    handleSubmit () {
      let params={bkyxsm:this.queryParam.bkyxsm,zsnj:this.queryParam.zsnj}
      let _this=this
      this.$confirm({
         title: '确定提交?',
         onOk() {
           _this.$api.doctorRecruit.enrollSupport(params).then(res=>{
            _this.loadData({
              pageSize:10,
              pageNum:_this.pagination.current
            })
      })
         },
         onCancel() {
           console.log('Cancel');
         },
         class: 'test',
       });

    },
    // 关闭审查弹层
    handleReviewClose () {
      this.planReviewVisible = false
      this.loadData({
        pageSize:10,
        pageNum:this.pagination.current
      })
    },
    // 保存
    handleReviewSuccess () {
      this.planReviewVisible = false
      this.$message.success('修改成功')
      this.loadData({
        pageSize:10,
        pageNum:this.pagination.current
      })
    },
       // 关闭考生想去
    handleClosePreview () {
      this.previewVisible = false

    },
    handlePreview(record){
      let id=record.id;
      this.$api.doctorRecruit.infoId(id).then(res =>{
        this.examineeData=res.data;
      })
      this.previewVisible = true
    },
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
